<template>
  <div class="login">
    <div class="wrap">
      <div class="logo">
        <img src="@/assets/home/logo.png" alt />
      </div>
      <div class="box">
        <div>
          <img src="@/assets/login/login_pic_1.png" alt />
        </div>
        <div class="form">
          <el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="0px">
            <div class="input">
              <el-form-item label prop="phone">
                <el-input
                  prefix-icon="el-icon-mobile-phone"
                  v-model="ruleForm.phone"
                  placeholder="请输入手机号"
                ></el-input>
              </el-form-item>
            </div>
            <div class="input">
              <el-form-item label prop="pass">
                <el-input
                  prefix-icon="el-icon-lock"
                  v-model="ruleForm.pass"
                  placeholder="请输入密码"
                  show-password
                ></el-input>
              </el-form-item>
            </div>
            <div class="check">
              <el-form-item label>
                <el-checkbox v-model="ruleForm.checked">记住密码</el-checkbox>
              </el-form-item>
              <div>忘记密码</div>
            </div>
            <div class="btn">
              <el-button @click="to('/home')" type="success" size="medium">登录</el-button>
              <el-button @click="to('/reg')" size="medium">注册</el-button>
            </div>
          </el-form>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: "login",
  data() {
    var validatePass = (rule, value, callback) => {
      if (value === "") {
        callback(new Error("请输入密码"));
      } else {
        if (this.form.pass !== "") {
          this.$refs.form.validateField("checkPass");
        }
        callback();
      }
    };
    return {
      ruleForm: {
        phone: "",
        pass: "",
        checked: false
      },
      rules: {
        phone: [
          { required: true, message: "请输入手机号", trigger: "blur" },
          {
            len: 11,
            message: "手机号格式不正确",
            trigger: "blur"
          }
        ],
        pass: [
          { validator: validatePass, required: true, trigger: "blur" },
          { min: 6, max: 12, message: "密码长度为6-12位", trigger: "blur" }
        ]
      }
    };
  },
  methods: {
    to(e) {
      // console.log(e);
      if (e === "/home") {
        this.$refs["ruleForm"].validate(valid => {
          if (valid) {
            this.$http
              .post(
                "http://192.168.10.38:9999/admin/detailsUser",
                this.ruleForm
              )
              // .then(res => {
              //   // console.log(res);
              // });
            // this.$router.push(e)
          } else {
            // console.log("error submit!!");
            return false;
          }
        });
      } else {
        this.$router.push(e);
      }
    }
  },
  components: {}
};
</script>
<style lang="scss" scoped >
@import "@/assets/css/index.scss";
.login {
  height: 100vh;
  background: url(../assets/login/web_login_reg_bg.jpg) no-repeat;
  background-size: 100% 100%;
  display: flex;
  justify-content: center;
  align-items: center;
  .wrap {
    width: 900px;
    height: 480px;
    box-sizing: border-box;
    background: $navbg;
    border-radius: 10px;
    padding: 0 50px;
    .logo {
      padding: 30px;
      img {
        width: 168px;
        height: 38px;
      }
    }
    .box {
      display: flex;
      justify-content: space-between;
      img {
        width: 390px;
        height: 320px;
      }
      .form {
        width: 300px;
        .input {
          margin-bottom: 30px;
        }
        .check {
          display: flex;
          justify-content: space-between;
          margin-bottom: 35px;
          font-size: 12px;
          color: $stxt;
          div:nth-of-type(1) {
            width: 200px;
          }
        }
        .btn {
          display: flex;
          flex-direction: column;
          align-items: center;
        }
      }
    }
  }
}
</style>
<style>
.login .btn button {
  width: 95%;
  margin-bottom: 20px;
}
.login .check .el-checkbox__label {
  font-size: 12px;
}
.login .el-button + .el-button {
  margin-left: 0;
}
</style>
